﻿using System;
using System.Windows;
using System.Windows.Threading;
using MultiViewer.Network;
using System.Diagnostics;

namespace MultiViewer.Display
{
    public class MultiViewerApplication : Application
    {
        private string[] args;

        public MultiViewerApplication()
        {
            DispatcherUnhandledException += OnUnhandledException;
        }

        protected override void OnStartup(StartupEventArgs e)
        {
            args = e.Args;
            base.OnStartup(e);
        }

        public string[] Arguments
        {
            get
            {
                return args;
            }
        }

        private void OnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            UnhandlerExceptionWindow w = new UnhandlerExceptionWindow();
            w.SetExceptionData(e.Exception);
            w.ShowDialog();
            e.Handled = true;
            Process.GetCurrentProcess().Kill(); // Terminate current process immediately
        }
    }
}